<template>
  <view class="page">
		<view class="header">
			<view class="uni-search-bar">
				<uni-search-bar placeholder="请输入关键字进行查找"  cancel-button="none" radius="100"/>
			</view>
		</view>
		<view class="classify_wrap">
			<!-- 横向分类滚动开始 -->
			<view class="classify_scroll_x">
				<scroll-view scroll-x="true" >
					<view class="segmented-wrap">
						<uni-segmented-control :current="current" :values="classify" @clickItem="onClickItem" styleType="text" activeColor="#CC0000"></uni-segmented-control>
					</view>
				</scroll-view>
			</view>
			<!-- 横向分类滚动结束 -->
			<view class="classify_icon" @click="goToGridPage()">
				<uni-icons type="list" size="28" color="gray"></uni-icons>
			</view>
		</view>
		
		<view class="content">
			<view v-if="current === 0">
				<!-- 会员权益开始 -->
				<view class="vip-wrap">
					<uni-card title="会员权益" :thumbnail="vipIcon" margin="5px">
						<uni-grid :column="column" :show-border="false" :square="false">
							<uni-grid-item v-for="(item, index) in vipItem">
								<view class="grid-item-box">
									<image :src="item.icon" style="width: 60rpx; height: 60rpx;" mode="aspectFill"></image>
									<text>{{ item.text }}</text>
								</view>
							</uni-grid-item>
						</uni-grid>
					</uni-card>
				</view>
				<!-- 会员权益结束 -->
				<!-- 名医药膳列表开始 -->
				<view class="bookList">
					<unicloud-db v-slot:default="{data, loading, error, options}" collection="medicine" where="classify=='名医药膳'">
						<view v-if="error">{{error.message}}</view>
						<view v-else>
							<uni-list>
								<uni-list-item v-for="(item, index) in data">
								  <template v-slot:header>
								    <view class="slot-box">
								      <image class="slot-image" v-if="item.coverImage && item.coverImage.url" :src="item.coverImage.url" mode="widthFix"></image>
								    </view>
								  </template>
								  <template v-slot:body>
								      <view class="medicineName">
								        <text>{{item.medicineName}}</text>
								      </view>
								      <view class="author">
								        <text>发货地 | {{ item.author }}</text>
								        <text>厂家 | {{ item.brand }}</text>
								      </view>
								      <view class="price">
								        <text class="cheapPrice">¥ {{ getYuan(item.cheapPrice) }}</text>
								        <text>&nbsp;</text>
								        <text class="bookPrice"> ¥ {{ getYuan(item.price) }}</text>
								      </view>
								    </template>
								</uni-list-item>	
							</uni-list>
							
						</view>
					</unicloud-db>
				</view>
				<!-- 名医药膳列表结束 -->
			</view>
			<view v-if="current === 1">
				<!-- 惠捷自选列表开始 -->
				<view class="bookList">
					<unicloud-db v-slot:default="{data, loading, error, options}" collection="medicine" where="classify=='惠捷自选'">
						<view v-if="error">{{error.message}}</view>
						<view v-else>
							<uni-list>
								<uni-list-item v-for="(item, index) in data">
								  <template v-slot:header>
								    <view class="slot-box">
								      <image class="slot-image" v-if="item.coverImage && item.coverImage.url" :src="item.coverImage.url" mode="widthFix"></image>
								    </view>
								  </template>
								  <template v-slot:body>
								      <view class="medicineName">
								        <text>{{item.medicineName}}</text>
								      </view>
								      <view class="author">
								        <text>发货地 | {{ item.author }}</text>
								        <text>厂家 | {{ item.brand }}</text>
								      </view>
								      <view class="price">
								        <text class="cheapPrice">¥ {{ getYuan(item.cheapPrice) }}</text>
								        <text>&nbsp;</text>
								        <text class="bookPrice"> ¥ {{ getYuan(item.price) }}</text>
								      </view>
								    </template>
								</uni-list-item>	
							</uni-list>
						</view>
					</unicloud-db>
				</view>
				<!-- 惠捷自选列表结束 -->
			</view>
			<view v-if="current === 2">
				<!-- 药品速购列表开始 -->
				<view class="bookList">
					<unicloud-db v-slot:default="{data, loading, error, options}" collection="medicine" where="classify=='药品速购'">
						<view v-if="error">{{error.message}}</view>
						<view v-else>
							<uni-list>
								<uni-list-item v-for="(item, index) in data">
								  <template v-slot:header>
								    <view class="slot-box">
								      <image class="slot-image" v-if="item.coverImage && item.coverImage.url" :src="item.coverImage.url" mode="widthFix"></image>
								    </view>
								  </template>
								  <template v-slot:body>
								      <view class="medicineName">
								        <text>{{item.medicineName}}</text>
								      </view>
								      <view class="author">
								        <text>发货地 | {{ item.author }}</text>
								        <text>厂家 | {{ item.brand }}</text>
								      </view>
								      <view class="price">
								        <text class="cheapPrice">¥ {{ getYuan(item.cheapPrice) }}</text>
								        <text>&nbsp;</text>
								        <text class="bookPrice"> ¥ {{ getYuan(item.price) }}</text>
								      </view>
								    </template>
								</uni-list-item>	
							</uni-list>
						</view>
					</unicloud-db>
				</view>
				<!-- 药品速购列表结束 -->
			</view>
			<view v-if="current === 3">
				<!-- 新药速递列表开始 -->
				<view class="bookList">
					<unicloud-db v-slot:default="{data, loading, error, options}" collection="medicine" where="classify=='新药速递'">
						<view v-if="error">{{error.message}}</view>
						<view v-else>
							<uni-list>
								<uni-list-item v-for="(item, index) in data">
								  <template v-slot:header>
								    <view class="slot-box">
								      <image class="slot-image" v-if="item.coverImage && item.coverImage.url" :src="item.coverImage.url" mode="widthFix"></image>
								    </view>
								  </template>
								  <template v-slot:body>
								      <view class="medicineName">
								        <text>{{item.medicineName}}</text>
								      </view>
								      <view class="author">
								        <text>发货地 | {{ item.author }}</text>
								        <text>厂家 | {{ item.brand }}</text>
								      </view>
								      <view class="price">
								        <text class="cheapPrice">¥ {{ getYuan(item.cheapPrice) }}</text>
								        <text>&nbsp;</text>
								        <text class="bookPrice"> ¥ {{ getYuan(item.price) }}</text>
								      </view>
								    </template>
								</uni-list-item>	
							</uni-list>
						</view>
					</unicloud-db>
				</view>
				<!-- 新药速递列表结束 -->
			</view>
			<view v-if="current === 4">
				<!-- 换药室列表开始 -->
				<view class="bookList">
					<unicloud-db v-slot:default="{data, loading, error, options}" collection="medicine" where="classify=='换药室'">
						<view v-if="error">{{error.message}}</view>
						<view v-else>
							<uni-list>
								<uni-list-item v-for="(item, index) in data">
								  <template v-slot:header>
								    <view class="slot-box">
								      <image class="slot-image" v-if="item.coverImage && item.coverImage.url" :src="item.coverImage.url" mode="widthFix"></image>
								    </view>
								  </template>
								  <template v-slot:body>
								      <view class="medicineName">
								        <text>{{item.medicineName}}</text>
								      </view>
								      <view class="author">
								        <text>发货地 | {{ item.author }}</text>
								        <text>厂家 | {{ item.brand }}</text>
								      </view>
								      <view class="price">
								        <text class="cheapPrice">¥ {{ getYuan(item.cheapPrice) }}</text>
								        <text>&nbsp;</text>
								        <text class="bookPrice"> ¥ {{ getYuan(item.price) }}</text>
								      </view>
								    </template>
								</uni-list-item>	
							</uni-list>
						</view>
					</unicloud-db>
				</view>
				<!-- 换药室列表结束 -->
			</view>
			
		</view>
		
	</view>
</template>

<script>
  export default {
    data() {
      return {
				classify:["名医药膳","惠捷自选","药品速购","新药速递","换药室"],
				current: 0,
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				Data:[],
				
				
				column: 3,
					vipIcon: '/static/shop/yiliao.png',
					vipItem: [
						{text: '医保卡消费', icon: '/static/shop/yibaokaxiaofei.png'},
						{text: '购买记录', icon: '/static/shop/goumaijilu.png'},
						{text: '药量记录', icon: '/static/shop/yaoliangjilu.png'}
					],
      }
    },
    methods: {
		getYuan(data){
			let yuan = Math.floor(data / 100)
			let fen = data % 100
			if(fen == 0) fen = "00"
			return yuan+'.'+fen
		  },
		onClickItem(e) {
			if (this.current !== e.currentIndex) {
				this.current = e.currentIndex
			}
		},
		goToGridPage(){
			uni.switchTab({
				url:'/pages/grid/grid'
			})
		},
    }
  }
  

</script>

<style scoped>
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}
	.page{
		background-color: #EEEEEE;
	}
	.header{
		display: flex;
		flex-direction: row;
		background-color: #FFFFFF;
	}
	.locationName{
		display: flex;
		flex-direction: row;
		height: 50px;
		line-height: 50px;
		font-size: 12px
	}
	.uni-search-bar{
		width: 100%;
		height: 50px;
	}
	.classify_wrap {
		width: 100%;
		display: flex;
		flex-direction: row;
	}
	.classify_scroll_x{
		white-space: nowrap;
		width: 650rpx;
		background-color: #FFFFFF;
		margin-top: 5rpx;
		margin-bottom: 8rpx;
	}
	.classify_icon{
		display: flex;
		flex: 1;
		background-color: #FFFFFF;
		margin-left: 2rpx;
		margin-top: 5rpx;
		margin-bottom: 8rpx;
	}
	.segmented-wrap{
		width: 1300rpx;
	}
	.scroll-view-item_H {
		display: inline-block;
		width: 140rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 12rpx;
	}
	.scroll-view-item_selected{
		border-bottom: 2px solid red;
	}
	.uni-margin-wrap{
		margin-top: 5rpx;
	}
	.swiper{
		height: 315rpx;
	}
	.banner-image {
		width: 750rpx;
		height: 315rpx;
	}
	.grid-item-box {
		text-align: center;
		justify-content: center;
		padding: 20rpx 0 0 0;
	}
	.grid-item-box image{
		margin: 0 auto;
	}
	.slot-box {
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	}
	
	.slot-image {
	  display: block;
	  margin-right: 10px;
	  width: 200rpx;
	  height: 200rpx;
	}
	.medicineName{
	  font-size: 30rpx;
	  display: -webkit-box;
	  line-height: 1.5em;
	  -webkit-box-orient: vertical;
	  -webkit-line-clamp: 2;
	  overflow: hidden;
	  text-overflow: ellipsis;
	  margin-bottom: 5rpx;
	}
	.author{
	  font-size: 24rpx;
	  white-space: nowrap; /* 禁止换行 */
	  overflow: hidden; /* 隐藏溢出内容 */
	  text-overflow: ellipsis; /* 使用省略号表示文本溢出 */
	  word-break: break-all; /* 允许在单词内换行 */
	  margin-bottom: 10rpx;
	  color: #666666;
	}
	.price {
	  display: flex;
	  flex-direction: row;
	  line-height: 40rpx;
	}
	.cheapPrice{
	  font-size: 40rpx;
	  color: #000000;
	}
	.bookPrice{
	  font-size: 24rpx;
	  color: #AAAAAA;
	  text-decoration-line: line-through;
	}
</style>